<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    shift unshift
</body>

<script>
    Object.print = function () {
        console.log("对象本身的print", this);
    }
    Object.prototype.print = function () {
        console.log("实例的方法print", this);
    }

    var obj = new Object();
    obj.print();
    Object.print()

    var value = Object(true);
    console.log(value);

    var obj1 = new Object([123, 123]);
    console.log(obj1 instanceof Object);
    console.log(obj1 instanceof Array);

    var obj = Object.defineProperties({}, {
        p1: { value: 1, enumerable: true },
        p2: { value: 2, enumerable: false }
    });

    console.log(Object.getOwnPropertyNames(obj)) // ['p1', 'p2']
    console.log(Object.keys(obj)) // ['p1']

    var arr = [1, 2, 3];
    console.log(arr.join("").toString())

    console.log("====== this指向 ======");

    var o = {
        f1: function () {
            console.log(this);
            (function () {
                console.log();
            })();
        }
    }
    o.f1()

    console.log("====== 立即执行函数 ======");

    var len = 117;
    let func = {
        len: 935,
        showLen: function () {
            console.log(this.len);
        },
        show: function () {
            // (function (cb) {
            //     cb();
            // })(this.showLen)
            const f = function (cb) {
                console.log(this);
                cb();
            }
            console.log(this);
            f(this.showLen)
        }
    }
    func.show();


    console.log("====== 立即执行函数 ======");
    var obj = {
        number: 3,
        w: dd = 99,
        xxx: (function () {
            console.log(this + '-----------')//立即执行函数中的this指向window，因为立即执行函数是window调用的            
            console.log(dd + '^^^^^^^^^^^')// 99
            // console.log(number + '***************')// 会报错：number is not defined，后面的代码就不会执行了
            console.log(this.number + '~~~~~~~~~~~')//删除上面一行，此处this.number返回undefined
            this.number += 4;// 值为NaN(undefined+4返回NaN)
            return function () {
                console.log("里面");
                console.log(this.number + '】】】】】】】】')
                this.number += 7;
                console.log(this + '++++++++++++++++++++++')
            }
        })()//立即执行函数
    }
    console.log("----------------------");
    obj.xxx() //相当于obj.xxx.call()，所以此处的this指向obj
    console.log("----------------------");
    console.log(obj.number) //10


    console.log("----------------------");
    function X() {
        return object = {
            name: 'object',
            f1(x) {
                console.log("start1");
                console.log('^^^^^^^^^')
                console.log(x)//此处的x为options
                console.log(this)
                console.log('^^^^^^^^^')
                console.log('】】】】】】】')
                console.log(x.f2())//会调用B，打印出options
                console.log('】】】】】】】')
                console.log("end1");
                x.f2()
            },
            f2() {
                console.log('~~~~~~~~~~~~')
                console.log(this)
                console.log('~~~~~~~~~~~~')
            }
        }
    }
    var options = {
        name: 'options',
        f1() { },
        f2() {
            console.log('%%%%%%%%%%%%%%%%%%')
            console.log(this) // B
            console.log('%%%%%%%%%%%%%%%%%%')
        }
    }
    var x = X()
    x.f1(options)//可以写为： x.f1.call(x,options)    

</script>

</html>